package com.itheima.consumer.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Normalconfiguration {


    //定义一个普通fanout交换机(两种方式)
    @Bean
    public DirectExchange normalExchange() {
    return ExchangeBuilder.directExchange("normal.direct").build();  //用ExchangeBuilder这个接口调用实现类build出来
    }

    //创建普通队列并与死信交换机绑定
    @Bean
    public Queue normalQueue() {

        return QueueBuilder
                .durable("normal.queue1")// build出来 durable将会持久化到磁盘,让消息持久化
                .deadLetterExchange("dlx.direct") //deadLetterExchange绑定死信交换机
                .build();
    }

    //绑定普通队列和普通交换机关系 with:routingKey
    @Bean
    public Binding normalExchangeBinding() {
        return BindingBuilder.bind(normalQueue()).to(normalExchange()).with("hi");
    }

}
